<?php

function genUUID() {
	return "uuid".md5(uniqid(mt_rand(), true));
}

class field {
	
	public $value;
	public $name;
	public $onchange;
}

class entity {
	
	protected $fields = array();
	
	function __construct() {
		$field = new field();
		$field->name = "uuid";
		$this->fields[] = $field;
	}
	
	function __set($name, $value) {
		foreach ($this->fields as $field) {
			if ($name == $field->name) {
				$field->value = $value;
				eval($field->onchange);
			}
		}
	}
	
	function __get($name) {
		foreach ($this->fields as $field) {
			if ($name == $field->name) {
				return $field->value;
			}
		}
	}
}

class dictionary extends entity {

	function __construct() {
		parent::__construct();
		$field = new field();
		$field->name = "name";
		$this->fields[] = $field;
	}
}

class Tovar extends dictionary {
	
	protected $uuid = "uuid1815ecd6cd133026ce44c905ee5a70f6";
	
	function __construct() {
		parent::__construct();
		$field = new field();
		$field->name = "priceP";
		$field->onchange = '$this->priceR = $this->priceP * 1.25;';
		$this->fields[] = $field;
		$field = new field();
		$field->name = "priceR";
		$this->fields[] = $field;
	}
}

class Sotrud extends dictionary {
	
	protected $uuid = "uuid1815ecd6cd133078ce44c905ee5a70f6";
	
	function __construct() {
		parent::__construct();
		$field = new field();
		$field->name = "surname";
		$this->fields[] = $field;
		$field = new field();
		$field->name = "bithday";
		$this->fields[] = $field;
	}
}



$tov = new Tovar();
$tov->name = "Молоко";
$tov->priceP = "5.6";

$sotr = new Sotrud();
$sotr->name = "name";
$sotr->surname = "surname";

echo "<pre>".print_r($tov,1)."</pre>";
echo "<pre>".print_r($sotr,1)."</pre>";

?>

